package servlet;

import dao.AttendanceDao;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet("/delete_attendance")
public class delete_attendance extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    protected void doGet(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, java.io.IOException {

        response.setContentType("text/html;charset=utf-8");
        response.setCharacterEncoding("utf-8");
        request.setCharacterEncoding("utf-8");

        PrintWriter out = response.getWriter();
        HttpSession session = request.getSession();
        AttendanceDao attendanceDao = new AttendanceDao();

        String teacher_id = request.getParameter("teacher_id");
        String attendance_time = request.getParameter("attendance_time");

        try {
            attendanceDao.deleteAttendance(attendance_time, teacher_id);
            session.setAttribute("teacher_id", teacher_id);
            response.sendRedirect("one_page_attendance");
        }
        catch (Exception e){
            out.print(e);
        }
    }

}
